package com.yoga.controller;

import com.yoga.entity.YogaCoach;
import com.yoga.entity.YogaPrivaterequest;
import com.yoga.entity.YogaUser;
import com.yoga.service.CoachService;
import com.yoga.service.UserService;
import com.yoga.utils.ResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

//@Component
@RestController
public class CoachController {
    @Autowired
    private CoachService coachService;
    @Autowired
    private UserService userService;

    //教练列表
    @RequestMapping("coachList")
    public ResultVO coachList() {
        List<YogaCoach> list = coachService.getAllCoach();
        return ResultVO.success("查询成功", list);
    }

    //根据教练表查用户表
    @RequestMapping("coachListByuid")
    public ResultVO coachListByuid() {
        List<YogaCoach> list = coachService.getAllCoach();
        List<YogaUser>  usersList = new ArrayList<YogaUser>();
        for (YogaCoach user : list){
            usersList.add(userService.getUserById(user.getUid()));
        }
        return ResultVO.success("查询成功", usersList);
    }

    //
    @RequestMapping("coachByuid")
    public ResultVO coachByuid(Integer uid) {
        YogaUser user = userService.getUserById(uid);
        return ResultVO.success("查询成功", user);
    }

    //改变订单状态
    @RequestMapping("changeClassState")
    public ResultVO changeClassState(Integer pqid, Integer stateCode){
        //stateCode为前端选择的课程状况，1为已确认，2为已取消，3为待支付
            coachService.changeClassState2Ready(pqid, stateCode);
            return ResultVO.success("修改课程情况成功");
    }

    //根据教练ID查询课程列表
    @RequestMapping("findCoachClass")
    public ResultVO findCoachClass(Integer coachuid){
        List<YogaPrivaterequest> myClassList = coachService.findMyClass(coachuid);
        return ResultVO.success("查询成功",myClassList);
    }

}
